﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Xrm.Solutions.FrameworkSample.Common;

namespace Xrm.Solutions.FrameworkSample.UnitTests
{
    [TestClass]
    public class SimpleMoqUnitTest
    {
        [TestMethod]
        public void TestMoq()
        {
            //Create
            Mock<IIdentityCheckService> identityServiceMock = new Mock<IIdentityCheckService>();

            //Setup
            identityServiceMock.Setup(service => service.RunCheck(It.IsAny<string>(),
                                                    It.IsAny<string>(),
                                                    It.IsAny<DateTime>(),
                                                    It.IsAny<string>())
                    ).Returns(60);

            //Setup 1
            identityServiceMock.Setup(service => service.RunCheck(It.IsAny<string>(),
                                                    It.IsAny<string>(),
                                                    It.IsAny<DateTime>(),
                                                    It.IsIn<string>("London"))
                    ).Returns(80);

            //Setup 2
            identityServiceMock.Setup(service => service.RunCheck("Wael",
                                                                "Hamze",
                                                                new DateTime(1990, 01, 01),
                                                                "10 South Colonnade")
                    ).Returns(99);

            //Verify

            IIdentityCheckService identityService = identityServiceMock.Object;

            int score = identityService.RunCheck("Wael",
                                    "Hamze",
                                    new DateTime(1990, 01, 01),
                                    "10 South Colonnade");

            Assert.AreEqual(score, 99);

            score = identityService.RunCheck("Test",
                        "Customer",
                        new DateTime(1990, 01, 01),
                        "London");

            Assert.AreEqual(score, 80);

            score = identityService.RunCheck("Test",
            "Customer",
            new DateTime(1990, 01, 01),
            "UK");

            Assert.AreEqual(score, 60);
        }
    }
}
